<template>
    <view class="beach-info">
        <view class="back-box" @click="hideShow">
            <uni-icons class="back-icon" type="left" size="20" color="#fff"></uni-icons>
        </view>
        <view class="top-photo-box">
            <view class="photo-box">
                <image src="/static/diary-bg.png"></image>
            </view>
            <image class="box-bg" src="/static/photo-bg.png"></image>
        </view>
        <view class="text-box flex-item-center">
            <view class="name-label">水懒</view>
            <view>酒馆里弥漫着，紫醉金迷的香味</view>
        </view>
        
        <!-- 消息列表区域 -->
        <view class="messages-box">
            <view class="tips-box flex-item-center" v-for="(message, index) in messages" :key="index">
                <view class="face-box flex-item-center">
                    <image :src="message.avatar || '/static/default-avatar.png'"></image>
                </view>
                <view>{{ message.content }}</view>
            </view>
        </view>
        
        <!-- 输入区域 -->
        <view class="write-box flex-item-center" @click="showInput">
            <image src="/static/input-icon.png"></image>我来说说…...
        </view>
        
        <!-- 输入框模态框 -->
        <view class="input-modal" v-if="showInputModal">
            <view class="modal-content">
                <view class="modal-header">
                    <text>发表评论</text>
                    <text class="close-btn" @click="hideInputModal">取消</text>
                </view>
                <textarea 
                    class="comment-input" 
                    v-model="commentText" 
                    placeholder="我来说说..." 
                    auto-height 
                ></textarea>
                <view class="modal-footer">
                    <button class="send-btn" @click="sendComment" :disabled="!commentText.trim()">发送</button>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
export default {
    data() {
        return {
            showInputModal: false,
            commentText: '',
            messages: [
                {
                    avatar: '',
                    content: '水懒，你也太可爱啦！'
                }
            ]
        }
    },
    methods: {
        hideShow() {
            this.$emit('hideShow')
        },
        showInput() {
            this.showInputModal = true
        },
        hideInputModal() {
            this.showInputModal = false
            this.commentText = ''
        },
        sendComment() {
            const content = this.commentText.trim()
            if (!content) return
            
            // 添加新消息
            this.messages.push({
                avatar: '/static/user-avatar.png', // 假设这是用户头像
                content: content
            })
            
            // 清空输入并关闭模态框
            this.commentText = ''
            this.showInputModal = false
            
            // 可以在这里添加发送到服务器的逻辑
            this.sendToServer(content)
        },
        sendToServer(content) {
            // 这里实现实际的网络请求逻辑
            console.log('发送评论到服务器:', content)
            // uni.request({
            //     url: 'your-api-url',
            //     method: 'POST',
            //     data: { content },
            //     success: (res) => {
            //         console.log('评论发送成功', res)
            //     },
            //     fail: (err) => {
            //         console.error('评论发送失败', err)
            //         // 可以添加失败处理逻辑，如显示提示、回滚消息等
            //     }
            // })
        }
    }
}
</script>

<style lang="less" scoped>
.beach-info {
    height: 100vh;
    background-color: rgba(255,255,255, .1);
    padding-top: 30rpx;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999;
    backdrop-filter: blur(10px);
    
    .back-box {
        width: 52rpx;
        height: 52rpx;
        border-radius: 50%;
        background-color: rgba(0,0,0,0.18);
        backdrop-filter: blur(10px);
        position: absolute;
        left: 42rpx;
        .back-icon {
            margin-top: 4rpx;
            display: block;
        }
    }
    
    .top-photo-box {
        margin: 100rpx auto 0;
        width: 592rpx;
        height: 518rpx;
        overflow: hidden;
        .box-bg {
            margin-top: -114rpx;
            width: 100%;
            height: 268rpx;
        }
        .photo-box {
            width: 100%;
            height: 364rpx;
            padding: 20rpx 25rpx;
            background-color: #fff;
            border-radius: 20rpx;
            image {
                width: 100%;
                height: 100%;
                border-radius: 15rpx;
            }
        }
    }
    
    .text-box {
        margin: 64rpx auto 0;
        font-size: 32rpx;
        background: url('/static/txt-bg.png') no-repeat;
        background-size: 100%;
        width: 658rpx;
        height: 205rpx;
        justify-content: center;
        position: relative;
        .name-label {
            position: absolute;
            top: -22rpx;
            right: 34rpx;
            width: 117rpx;
            height: 64rpx;
            line-height: 64rpx;
            background: url('/static/name-label-bg.png') no-repeat;
            background-size: 100%;
            font-size: 24rpx;
            text-align: center;
            color: #fff;
        }
    }
    
    .messages-box {
        margin: 30rpx auto 0;
        max-height: 400rpx;
        overflow-y: auto;
        padding: 0 40rpx;
    }
    
    .tips-box, .write-box {
        margin: 20rpx auto;
        width: 650rpx;
        height: 110rpx;
        background: url('/static/comm-bg.png') no-repeat;
        background-size: 100%;
        font-size: 24rpx;
        color: #999;
        .face-box {
            margin-right: 32rpx;
            width: 96rpx;
            height: 97rpx;
            background: url('/static/face-bg.png') no-repeat;
            background-size: 100%;
            justify-content: center;
            image {
                width: 66rpx;
                height: 66rpx;
                border-radius: 50%;
            }
        }
    }
    
    .write-box {
        position: fixed;
        bottom: 50rpx;
        left: 50%;
        transform: translateX(-50%);
        justify-content: center;
        color: #000;
        image {
            margin-right: 16rpx;
            width: 40rpx;
            height: 40rpx;
        }
    }
    
    /* 输入框模态框样式 */
    .input-modal {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0,0,0,0.5);
        z-index: 1000;
        display: flex;
        justify-content: center;
        align-items: center;
        
        .modal-content {
            width: 650rpx;
            background-color: #fff;
            border-radius: 20rpx;
            overflow: hidden;
            
            .modal-header {
                height: 90rpx;
                line-height: 90rpx;
                padding: 0 30rpx;
                border-bottom: 1rpx solid #eee;
                display: flex;
                justify-content: space-between;
                font-size: 32rpx;
                
                .close-btn {
                    color: #999;
                    font-size: 28rpx;
                }
            }
            
            .comment-input {
                width: 100%;
                min-height: 200rpx;
                padding: 30rpx;
                font-size: 28rpx;
            }
            
            .modal-footer {
                padding: 20rpx 30rpx;
                display: flex;
                justify-content: flex-end;
                
                .send-btn {
                    background-color: #007AFF;
                    color: #fff;
                    border-radius: 10rpx;
                    padding: 10rpx 40rpx;
                    font-size: 28rpx;
                    
                    &:disabled {
                        background-color: #CCCCCC;
                    }
                }
            }
        }
    }
}

/* 工具类 */
.flex-item-center {
    display: flex;
    align-items: center;
}
</style>    